var host = 'https://chentao.mynatapp.cc/invoice';
// var host = 'https://www.shangjiatech.com/invoice';

function get(url) {
  return new Promise((resolv, reject) => {
    wx.request({
      url: host + url,
      method: "get",
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function(res) {
        if (res.status == "555") {
          wx.hideLoading()
          wx.showModal({
            title: '提示',
            content: res.msg,
          })
        } else {
          resolv(res.data)
        }
      },
      fail: function(err) {
        console.log(err)
        reject(err)
        wx.hideLoading()
        // wx.showModal({
        //   title: '提示',
        //   content: '网络错误或服务器繁忙!',
        // })
      }
    })
  })
}
 
function post(url, data) {
  return new Promise((resolv, reject) => {
    wx.request({
      url: host + url,
      data: data,
      method: "POST",
      header: {
        'Content-Type': 'application/json'
      },
      success: function(res) {
        if (res.status == "555") {
          wx.hideLoading()
          wx.showModal({
            title: '提示',
            content: res.msg,
          })
        } else {
          resolv(res.data)
        }
      },
      fail: function(err) {
        wx.hideLoading()
        console.log(err)
        reject(err)
        // wx.showModal({
        //   title: '提示',
        //   content: '网络错误或服务器繁忙!',
        // })
      }
    })
  })
}


module.exports = {
  host,
  get,
  post
}